#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
typedef struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
}TreeNode;
TreeNode* PreorderCreate(int* a,int* i)
{
    if (a[*i] == 0)
    {
        (*i)++;
        return NULL;
    }      
    TreeNode* root = (TreeNode*)malloc(sizeof(TreeNode));
    root->val = a[*i];
    (*i)++;
    root->left = PreorderCreate(a, i);
    root->right = PreorderCreate(a, i);
    return root;
}
 TreeNode* invertTree(TreeNode* root)
{
    if (root == NULL)
        return NULL;
    TreeNode* tmp = root->left;
    root->left = root->right;
    root->right = tmp;
    root->left = invertTree(root->left);
    root->right = invertTree(root->right);
    return root;
}

bool isSameTree(struct TreeNode* p,  TreeNode* q)
{
    if (!p && !q)
        return true;
    if (p == NULL || q == NULL)
        return false;
    if (p->val != q->val)
        return false;
    return isSameTree(p->left, q->left) && isSameTree(p->right, q->right);
}

bool isSymmetric(struct TreeNode* root)
{
    struct TreeNode* Tree = invertTree(root->left);
    return isSameTree(Tree, root->right);
}

//bool isSameTree(struct TreeNode* p, struct TreeNode* q)
//{
//    if (!p && !q)
//        return true;
//    if (p == NULL || q == NULL)
//        return false;
//    if (p->val != q->val)
//        return false;
//    return isSameTree(p->left, q->right) && isSameTree(p->right, q->left);
//}
//
//bool isSymmetric(struct TreeNode* root)
//{
//    return isSameTree(root->left, root->right);
//}
int main()
{
    int a[] = { 1,2,0,3,0,0,2,0,3,0,0 };
    int n = 0;
    TreeNode* root=PreorderCreate(a,&n);
    if (isSymmetric(root))
        printf("true\n");
    else
        printf("false\n");
    return 0;

}